<h2 style='text-align:center'>后台成员管理</h2>

<button id='MainAdminUser_Add'>添加管理员</button>
<div id='MainAdminUser_AddUserArea' style='display:none'>
	<div><input id='MainAdminUser_AddName' placeholder='用户名' /></div>
	<div><input id='MainAdminUser_AddPwd' type='password' placeholder='密码' /></div>
	<div><input id='MainAdminUser_AddInfo' placeholder='备注' /></div>
	<div>
		<button id='MainAdminUser_AddBtn'>添加</button>
		<button id='MainAdminUser_AddCancel'>取消</button>
	</div>
</div>


<div style='margin:20px auto' id='MainAdminUser_ListArea'>
	<div style='border-bottom:1px solid #999;margin:5px auto;display:flex'>
		<span style='margin:5px 10px '>a1</span>
		<span style='margin:5px 10px '>2018-12-12</span>
		<span style='flex:1;margin:5px 10px;word-break:break-all'>sdfsdfsfsdfsdfsfsdfsdfsfsdfsdfsfsdfsdfssdfsdfsfsdfsdfsfsdfsdfsfsdfsdfsfsdfsdfsf</span>
		<span style='margin:5px 10px '><button>删除</button></span>
	</div>
</div>



<script>

	MainAdminUser_GetAdminUserList();	//获取管理员列表


	//获取管理员列表
	function MainAdminUser_GetAdminUserList(sess_stat){
		$('#MainAdminUser_ListArea').html('');
		var sess_name = 'sess_GetAdminUserList';
		if(sess_stat){
			sessionStorage.sess_GetAdminUserList = '';
		}
		sca({type:'GetAdminUserList'},function(res){
			MainAdminUser_GetAdminUserList_Parse(res);
		},after_url,sess_name);
	}

	//解析管理员列表
	function MainAdminUser_GetAdminUserList_Parse(res){
		if(!/^\[{"id".*$/.test(res)){
			return;
		}
		var list = JSON.parse(res);
		var str = '';
		for(var i=0;i<list.length;i++){
			var t = new Date(list[i].ctime*1000);
			var Y = t.getFullYear();
			var m = t.getMonth()+1;
			var d = t.getDate();
			var time = Y+'-'+m+'-'+d;
			str += "<div style='border-bottom:1px solid #999;margin:5px auto;display:flex'>";
			str += "	<span style='margin:5px 10px '>"+list[i].name+"</span>";
			str += "	<span style='margin:5px 10px;color:#55a '>"+time+"</span>";
			str += "	<span style='flex:1;margin:5px 10px;word-break:break-all;color:#777'>"+list[i].remarks+"</span>";
			str += "	<span style='margin:5px 10px'><button onclick=MainAdminUser_UserDel("+list[i].id+")>删除</button></span>";
			str += "</div>";
		}
		$('#MainAdminUser_ListArea').html(str);
	}



	//删除管理用户
	function MainAdminUser_UserDel(id){
		CheckControl();	//确认操作
		var data = {
			type:'DelUser',
			id:id
		};
		Ajax2(data,function(res){
			if(res == 'ok'){
				A('操作成功！');
				sessionStorage.AdminUserList = '';
				MainAdminUser_GetAdminUserList(1);	//获取管理员列表
			}else{
				A('操作失败!');
			}
		},after_url);
	}




	//显示添加区域
	$('#MainAdminUser_Add').click(function(){
		$('#MainAdminUser_AddUserArea').show();
	});

	//隐藏添加区域
	$('#MainAdminUser_AddCancel').click(function(){
		$('#MainAdminUser_AddUserArea').hide();
	});

	//添加用户的提交
	$('#MainAdminUser_AddBtn').click(function(){
		var name = ChangeChar($('#MainAdminUser_AddName').val().trim());
		var pwd = ChangeChar($('#MainAdminUser_AddPwd').val().trim());
		var info = ChangeChar($('#MainAdminUser_AddInfo').val().trim());

		Field_Check(/^[a-z]\w{1,10}$/,name,'js非法用户名!');
		Field_Check(/^.{1,}$/,pwd,'js密码非法!');

		var data = {
			type:'AdminUserAdd',
			name:name,
			pwd:pwd,
			info:info
		};
		Ajax2(data,function(res){
			switch(res){
				case 'errm':
					A('缺少地区参数!');
					break;
				case 'err1':
					A('用户已存在或添加失败!');
					break;
				case 'ok':
					A('用户添加成功!');
					$('#MainAdminUser_AddName').val('');
					$('#MainAdminUser_AddPwd').val('');
					$('#MainAdminUser_AddInfo').val('');
					$('#MainAdminUser_AddUserArea').hide();
					MainAdminUser_GetAdminUserList(1);	//获取管理员列表
					break;
			}
		},after_url);

	});




</script>